package com.company.project.configurer;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.company.project.core.ProjectConstant;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/*
 * 集成Knife4j 在线文档功能
 * Restful API 访问路径:
 * http://IP:port/swagger-ui.html
 * 或者 http://IP:port/doc.html
 * eg:http://localhost:8080/doc.html
 */
@Configuration
@EnableSwagger2
@Profile({ "dev", "test", "prod" })
@EnableKnife4j //Knife4j增强注解，用于开启增强功能
public class SwaggerApiConfig {

	@Bean
	public Docket createRestApi() {
		return new Docket( DocumentationType.SWAGGER_2 ).apiInfo( apiInfo() ).select()
				.apis( RequestHandlerSelectors.basePackage( ProjectConstant.BASE_PACKAGE+"controller" ) ).paths( PathSelectors.any() ).build();
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title( "康养项目接口文档" ).termsOfServiceUrl( "" )
				.contact( new Contact( "LI", "", "258696309@qq.com" ) ).version( "1.0" ).description("康养项目接口").build();
	}
}